package com.polaris.live.adapter

import android.view.View
import com.blankj.utilcode.util.ColorUtils
import com.polaris.live.R
import com.polaris.live.common.adapter.BaseBindingAdapter
import com.polaris.live.common.adapter.VBViewHolder
import com.polaris.live.databinding.AdapterBeautyTitleBinding
import com.polaris.live.resp.back_resp.BeautyDataItem

class BeautyTitleAdapter : BaseBindingAdapter<AdapterBeautyTitleBinding, BeautyDataItem>() {

    private var selectPosition = 0

    override fun convert(holder: VBViewHolder<AdapterBeautyTitleBinding>, item: BeautyDataItem) {
        val position = holder.absoluteAdapterPosition
        holder.vb.apply {
            beautyTitleText.text = item.title
            if (position == selectPosition) {
                beautyTitleText.setTextColor(ColorUtils.getColor(R.color.white))
                beautyTitleUnline.visibility = View.VISIBLE
            } else {
                beautyTitleText.setTextColor(ColorUtils.getColor(R.color.ffffff_50))
                beautyTitleUnline.visibility = View.INVISIBLE
            }
        }
    }

    fun setSelect(position: Int) {
        selectPosition = position
        notifyDataSetChanged()
    }

    fun clearSelected() {
        if (selectPosition == -1) {
            return
        }
        val index = selectPosition
        selectPosition = -1
        notifyItemChanged(index)
    }

}